//
//  ByUISafetyPayRecordVC.m
//  chequanbao_ios
//
//  Created by mc on 2017/12/1.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByUISafetyPayRecordVC.h"

#import "ByApiSafety.h"

@interface ByUISafetyPayRecordVC ()
@property (nonatomic, strong) UIScrollView *scroll;
@end

@implementation ByUISafetyPayRecordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"支付信息";
    [self fetchData];
//    [self createViews];
    [self addLeftBackBarButtonItem];
}
- (void)viewSafeAreaInsetsDidChange{
    [super viewSafeAreaInsetsDidChange];
    self.scroll.top = self.view.safeAreaInsets.top;
    self.scroll.height = self.view.height - self.view.safeAreaInsets.bottom;
}

#pragma mark - getter
- (UIScrollView *)scroll {
    if (!_scroll) {
        _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
        _scroll.bounces = NO;
        _scroll.showsVerticalScrollIndicator = NO;
        [self.view addSubview:_scroll];
    }
    return _scroll;
}

#pragma mark -
- (void)fetchData{
    ByNetParamsModel *model = [[ByNetParamsModel alloc] init];
    model.insurance_id = self.insurance_id;
    [ByCoreToolAlert showLoadind:@"加载中..."];
    [ByApiSafety lookPayInfo:model success:^(ByNetBaseResult *result) {
        NSDictionary *dic = result.data;
        [self createViews:dic];
        [ByCoreToolAlert hideHud];
        
    } failure:^(ByNetBaseResult *result) {
        [ByCoreToolAlert showOnlyText:result.msg];
    }];
}

#pragma mark - 创建视图
- (void)createViews:(NSDictionary *)dic{
    
//    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(35, 64 + 30, SCREEN_WIDTH - 35 * 2, SCREEN_HEIGHT - 60 - 64)];
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor colorWithR:87 g:142 b:192];
    bgView.layer.borderWidth = 1;
    bgView.layer.borderColor = [UIColor colorWithR:103 g:118 b:170].CGColor;
    [self.scroll addSubview:bgView];
    bgView.layer.cornerRadius = 10.0;
    
    // 测试数据
    NSString *info = dic[@"text"];
    CGFloat width = SCREEN_WIDTH - 70;
    CGFloat height = [info getRectOfStringWithSize:CGSizeMake(width - 70, MAXFLOAT) font:14].size.height;
    UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, 30, width - 70, height)];
    [bgView addSubview:infoLabel];
    infoLabel.font = FONT(14);
    infoLabel.numberOfLines = 0;
    infoLabel.text = info;
    infoLabel.textColor = [UIColor whiteColor];
    
    // 第一张图（2:1）
    UIImageView *firstImg = [[UIImageView alloc] initWithFrame:CGRectMake(35, infoLabel.bottom + 30,width - 70, (width - 70) / 2)];
    [bgView addSubview:firstImg];
    [firstImg setImageWithURL:[NSURL URLWithString:BOYE_PICTURE_VIEW_URL(dic[@"img")]] placeholderImage:DEFAULT_IMAGE];
    
    // 第二张图 （1:1）
    UIImageView *secondImg = [[UIImageView alloc] initWithFrame:CGRectMake(55, firstImg.bottom + 30, width - 110,width - 110)];
    [bgView addSubview:secondImg];
    NSURL *secondUrl = [NSURL                       URLWithString:BOYE_PICTURE_VIEW_URL(dic[@"qrcode"])];
    [secondImg setImageWithURL:secondUrl placeholderImage:DEFAULT_IMAGE];
    
    bgView.frame = CGRectMake(35, 30, SCREEN_WIDTH - 70, secondImg.bottom + 30);
    
}

@end
